package com.microstrategy.database.hbase.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.microstrategy.database.hbase.model.RegionOfTableOnEachRSServer;

/**
 * private String memstoresize; // memstore size private String storesize; //
 * total size of store file size private String storenumber;
 * 
 * @author wlu
 * 
 */
public interface RegionOfTableOnEachRSMapper {
	final String INSERT = "REPLACE INTO RTRS (ts, rsname, tablename, regionname, "
			+ "memstoresize, storesize, storenumber, storefileindexsize) "
			+ "VALUES (#{obj.timestamp}, #{obj.rsname}, #{obj.tablename}, #{obj.regionname}, "
			+ "#{obj.memstoresize}, #{obj.storesize}, #{obj.storenumber},#{obj.storefileindexsize})";

	@Insert(INSERT)
	@Options(useGeneratedKeys = true, keyProperty = "obj.server")
	void insert(@Param("obj") RegionOfTableOnEachRSServer rtrs);

	final String SELECT_BY_ID = "SELECT * FROM RTRS WHERE timestamp = #{sel_ts}";

	@Select(SELECT_BY_ID)
	@Results(value = {
			@Result(property = "timestamp", column = "ts"),
			@Result(property = "rsname", column = "rsname"),
			@Result(property = "tablename", column = "tablename"),
			@Result(property = "regionname", column = "regionname"),
			@Result(property = "memstoresize", column = "memstoresize"),
			@Result(property = "storesize", column = "storesize"),
			@Result(property = "storenumber", column = "storenumber"),
			@Result(property = "storefileindexsize", column = "storefileindexsize") })
	RegionOfTableOnEachRSServer selectByTS(@Param("sel_ts") String ts);
	
	final String SELECT_RECENT_N = "SELECT * FROM RTRS ORDER BY ts LIMIT #{limit}";
	@Select(SELECT_RECENT_N)
	@Results(value = {
			@Result(property = "timestamp", column = "ts"),
			@Result(property = "rsname", column = "rsname"),
			@Result(property = "tablename", column = "tablename"),
			@Result(property = "regionname", column = "regionname"),
			@Result(property = "memstoresize", column = "memstoresize"),
			@Result(property = "storesize", column = "storesize"),
			@Result(property = "storenumber", column = "storenumber"),
			@Result(property = "storefileindexsize", column = "storefileindexsize") })
	List<RegionOfTableOnEachRSServer> selectRecent(@Param("limit") Integer limit);
}
